/*******************************************************************************
*   			Impacts of a Large-Scale Parenting Program: 				   *
*					Experimental Evidence from Chile						   *
********************************************************************************


	REQUIRES:	"${dt_final}panel_RR_indexes.dta"
	CREATES:	${out_tables}/T1_baseline_desc.xls
				
	WRITEN BY:  Italo Lopez  [italolop@usc.edu]

********************************************************************************
	Prepare data
*******************************************************************************/

	* Load data
	use "${dt_final}panel_RR_indexes.dta", clear


	* Establish macros for regressions

/*******************************************************************************
*   Set macros for regressions
*******************************************************************************/
	
	* Outcomes
	*-----------------------------------------------------------
	local childoutcomes  "zDCCSPunt zptevir_irtscore2 zt_score zcbcl_t_e zcbcl_t_i zibatt_sspi zibatt_ssai zibatt_sssr zas_raw_score" 
	local behaviors "home_score se_score disc_score" 
	local beliefs "zpstyle1 zpstyle2 zpstyle3 zPSCS zPSSS_family zPSSS_friends zPSSS_others zPSI_Distress zCESD zpacotis"	
	
	* Controls
	*-----------------------------------------------------------

	macro  def Xvar1 "i.age_year i.gender"  	
	macro  def Xvar2 "i.age_year i.gender inc_qtaut_old i.pc_edu_mdsfin hh_mem hh_tipo"  	
	macro  def Xvar2old "i.gender inc_qtaut_old i.pc_edu_mdsfin_old hh_mem hh_tipo"  

	
	* Parental characteristics: WAIS and BFI and imputed wais 
	*-----------------------------------------------------------

	macro def parent_cha4 "BFI_ext BFI_ope BFI_con BFI_neu BFI_agr wais2 flag_wais"
	
	
/*******************************************************************************
	Table 1: Baseline Characteristics
*******************************************************************************/


	putexcel set "${out_tables}/T1_Baseline_Desc.xls", replace sheet("T1")

	* Table setup
	putexcel B1 = "(1)"
	putexcel B2 = "Control"
	putexcel B3 = "Mean"
	putexcel C1 = "(2)"
	putexcel C2 = "NEP-B"
	putexcel C3 = "Mean"
	putexcel D1 = "(3)"
	putexcel D2 = "NEP-I"
	putexcel D3 = "Mean"
	putexcel E1 = "t-test"
	putexcel E2 = "p-value"
	putexcel E3 = "(1)-(2)"
	putexcel F1 = "t-test"
	putexcel F2 = "p-value"
	putexcel F3 = "(1)-(3)"
	putexcel A3  = "Household Characteristics at Baseline"
	putexcel A4  = "Caregiver is the mother(%)"
	putexcel A5  = "Caregiver's Education(%)"
	putexcel A6  = " Primary"
	putexcel A7  = "  Secondary Incomplete"
	putexcel A8  = "  Secondary Complete"
	putexcel A9  = "  Tertiary"
	putexcel A10  = "Single Mother"
	putexcel A11  = "Caregiver's Age"
	putexcel A13  = "  Hh'ld p.c. income (<40%)"
	putexcel A14  = "  Hh'ld p.c. income (US dollars)"
	putexcel A16  = "No. Observations"
	putexcel A18  = "Child Characteristics at Baseline"
	putexcel A19  = "Boys"
	putexcel A20  = "Age in months"
	putexcel A22  = "Birth Order"
	putexcel A23  = "  First"
	putexcel A24  = "  Second"
	putexcel A25  = "  Third or more"
	putexcel A26  = "No. Observations"

	* Computing descriptive statistics for caregiver 
	*-----------------------------------------------------------

	preserve
	keep if y==1
	
	// Caregiver is the mother
	su cuidador1 if TIPO_old==1
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel B4 = "`mean'%"
	
	local n = string(`r(N)',"%9.0f")
	putexcel B16 = "`n'"
	
	su cuidador1 if TIPO_old==2
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel C4 = "`mean'%"
	
	local n = string(`r(N)',"%9.0f")
	putexcel C16 = "`n'"
	
	su cuidador1 if TIPO_old==3
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel D4 = "`mean'%"
	
	local n = string(`r(N)',"%9.0f")
	putexcel D16 = "`n'"
	
	xi: xtreg cuidador1 i.TIPO_old,  fe i(CENTRO_SALUD)
	matlist r(table)
	matrix I =r(table)
	local p1 = string(I[4,1],"%9.3f")
	local p2 = string(I[4,2],"%9.3f")
	putexcel E4 = "`p1'"
	putexcel F4 = "`p2'"

	// Caregiver education
	su edu1 if TIPO_old==1
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel B6 = "`mean'%"
	
	su edu1 if TIPO_old==2
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel C6 = "`mean'%"
	
	su edu1 if TIPO_old==3
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel D6 = "`mean'%"
	
	xi: xtreg edu1 i.TIPO_old,  fe i(CENTRO_SALUD)
	matlist r(table)
	matrix I =r(table)
	local p1 = string(I[4,1],"%9.3f")
	local p2 = string(I[4,2],"%9.3f")
	putexcel E6 = "`p1'"
	putexcel F6 = "`p2'"

	su edu2 if TIPO_old==1
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel B7 = "`mean'%"
	
	su edu2 if TIPO_old==2
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel C7 = "`mean'%"
	
	su edu2 if TIPO_old==3
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel D7 = "`mean'%"
	
	xi: xtreg edu2 i.TIPO_old,  fe i(CENTRO_SALUD)
	matlist r(table)
	matrix I =r(table)
	local p1 = string(I[4,1],"%9.3f")
	local p2 = string(I[4,2],"%9.3f")
	putexcel E7 = "`p1'"
	putexcel F7 = "`p2'"

	su edu3 if TIPO_old==1
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel B8 = "`mean'%"
	su edu3 if TIPO_old==2
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel C8 = "`mean'%"
	su edu3 if TIPO_old==3
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel D8 = "`mean'%"
	xi: xtreg edu3 i.TIPO_old,  fe i(CENTRO_SALUD)
	matlist r(table)
	matrix I =r(table)
	local p1 = string(I[4,1],"%9.3f")
	local p2 = string(I[4,2],"%9.3f")
	putexcel E8 = "`p1'"
	putexcel F8 = "`p2'"

	su edu4 if TIPO_old==1
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel B9 = "`mean'%"
	su edu4 if TIPO_old==2
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel C9 = "`mean'%"
	su edu4 if TIPO_old==3
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel D9 = "`mean'%"
	xi: xtreg edu4 i.TIPO_old,  fe i(CENTRO_SALUD)
	matlist r(table)
	matrix I =r(table)
	local p1 = string(I[4,1],"%9.3f")
	local p2 = string(I[4,2],"%9.3f")
	putexcel E9 = "`p1'"
	putexcel F9 = "`p2'"

	// Caregiver single mother
	su singlem if TIPO_old==1
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel B10 = "`mean'%"
	su singlem if TIPO_old==2
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel C10 = "`mean'%"
	su singlem if TIPO_old==3
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel D10 = "`mean'%"
	xi: xtreg singlem i.TIPO_old,  fe i(CENTRO_SALUD)
	matlist r(table)
	matrix I =r(table)
	local p1 = string(I[4,1],"%9.3f")
	local p2 = string(I[4,2],"%9.3f")
	putexcel E10 = "`p1'"
	putexcel F10 = "`p2'"

	// Caregiver age 
	su CUIDADOR_EDAD_old if TIPO_old==1 & CUIDADOR_EDAD_old<100
	local mean = string(`r(mean)',"%9.1f")
	local sd = string(`r(sd)',"%9.2f")
	putexcel B11 = "`mean'"
	putexcel B12 = "(`sd')"
	su CUIDADOR_EDAD_old if TIPO_old==2 & CUIDADOR_EDAD_old<100
	local mean = string(`r(mean)',"%9.1f")
	local sd = string(`r(sd)',"%9.2f")
	putexcel C11 = "`mean'"
	putexcel C12 = "(`sd')"
	su CUIDADOR_EDAD_old  if TIPO_old==3 & CUIDADOR_EDAD_old<100
	local mean = string(`r(mean)',"%9.1f")
	local sd = string(`r(sd)',"%9.2f")
	putexcel D11 = "`mean'"
	putexcel D12 = "(`sd')"
	xi: xtreg CUIDADOR_EDAD_old i.TIPO_old if CUIDADOR_EDAD_old<100,  fe i(CENTRO_SALUD)
	matlist r(table)
	matrix I =r(table)
	local p1 = string(I[4,1],"%9.3f")
	local p2 = string(I[4,2],"%9.3f")
	putexcel E11 = "`p1'"
	putexcel F11 = "`p2'"

	// Household income below 40%
	su qt40 if TIPO_old==1
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel B13 = "`mean'%"
	su qt40  if TIPO_old==2
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel C13 = "`mean'%"
	su qt40  if TIPO_old==3
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel D13 = "`mean'%"
	xi: xtreg qt40  i.TIPO_old,  fe i(CENTRO_SALUD)
	matlist r(table)
	matrix I =r(table)
	local p1 = string(I[4,1],"%9.3f")
	local p2 = string(I[4,2],"%9.3f")
	putexcel E13 = "`p1'"
	putexcel F13 = "`p2'"

	// Household income in dollars 
	su inc_pcmon_old if TIPO_old==1
	local mean = string(`r(mean)'/500,"%9.1f")
	local sd = string(`r(sd)'/500,"%9.2f")
	putexcel B14 = "`mean'"
	putexcel B15 = "(`sd')"
	su inc_pcmon_old if TIPO_old==2
	local mean = string(`r(mean)'/500,"%9.1f")
	local sd = string(`r(sd)'/500,"%9.2f")
	putexcel C14 = "`mean'"
	putexcel C15 = "(`sd')"
	su inc_pcmon_old if TIPO_old==3
	local mean = string(`r(mean)'/500,"%9.1f")
	local sd = string(`r(sd)'/500,"%9.2f")
	putexcel D14 = "`mean'"
	putexcel D15 = "(`sd')"
	xi: xtreg inc_pcmon_old i.TIPO_old,  fe i(CENTRO_SALUD)
	matlist r(table)
	matrix I =r(table)
	local p1 = string(I[4,1],"%9.3f")
	local p2 = string(I[4,2],"%9.3f")
	putexcel E14 = "`p1'"
	putexcel F14 = "`p2'"

	restore

	* Computing child characteristics at Baseline 
	*-----------------------------------------------------------

	// Gender 
	su sexo if TIPO_old==1
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel B19 = "`mean'%"
	
	local n = string(`r(N)',"%9.0f")
	putexcel B26 = "`n'"
	
	su sexo if TIPO_old==2
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel C19 = "`mean'%"
	
	local n = string(`r(N)',"%9.0f")
	putexcel C26 = "`n'"
	
	su sexo if TIPO_old==3
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel D19 = "`mean'%"
	
	local n = string(`r(N)',"%9.0f")
	putexcel D26 = "`n'"
	
	xi: xtreg sexo i.TIPO_old,  fe i(CENTRO_SALUD)
	matlist r(table)
	matrix I =r(table)
	local p1 = string(I[4,1],"%9.3f")
	local p2 = string(I[4,2],"%9.3f")
	putexcel E19 = "`p1'"
	putexcel F19 = "`p2'"

	// Age in months 
	su EDAD_MESES_x_old if TIPO_old==1
	local mean = string(`r(mean)',"%9.1f")
	local sd = string(`r(sd)',"%9.2f")
	putexcel B20 = "`mean'"
	putexcel B21 = "(`sd')"
	
	su EDAD_MESES_x_old if TIPO_old==2
	local mean = string(`r(mean)',"%9.1f")
	local sd = string(`r(sd)',"%9.2f")
	putexcel C20 = "`mean'"
	putexcel C21 = "(`sd')"
	
	su EDAD_MESES_x_old  if TIPO_old==3
	local mean = string(`r(mean)',"%9.1f")
	local sd = string(`r(sd)',"%9.2f")
	putexcel D20 = "`mean'"
	putexcel D21 = "(`sd')"
	
	xi: xtreg EDAD_MESES_x_old i.TIPO_old,  fe i(CENTRO_SALUD)
	matlist r(table)
	matrix I =r(table)
	local p1 = string(I[4,1],"%9.3f")
	local p2 = string(I[4,2],"%9.3f")
	putexcel E20 = "`p1'"
	putexcel F20 = "`p2'"

	// Birth order  
	
	su bthord_old1 if TIPO_old==1
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel B23 = "`mean'%"
	
	su bthord_old1 if TIPO_old==2
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel C23 = "`mean'%"
	
	su bthord_old1 if TIPO_old==3
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel D23 = "`mean'%"
	
	xi: xtreg bthord_old1 i.TIPO_old,  fe i(CENTRO_SALUD)
	matlist r(table)
	matrix I =r(table)
	local p1 = string(I[4,1],"%9.3f")
	local p2 = string(I[4,2],"%9.3f")
	putexcel E23 = "`p1'"
	putexcel F23 = "`p2'"

	su bthord_old2 if TIPO_old==1
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel B24 = "`mean'%"
	su bthord_old2 if TIPO_old==2
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel C24 = "`mean'%"
	su bthord_old2 if TIPO_old==3
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel D24 = "`mean'%"
	xi: xtreg bthord_old2 i.TIPO_old,  fe i(CENTRO_SALUD)
	matlist r(table)
	matrix I =r(table)
	local p1 = string(I[4,1],"%9.3f")
	local p2 = string(I[4,2],"%9.3f")
	putexcel E24 = "`p1'"
	putexcel F24 = "`p2'"

	su bthord_old3 if TIPO_old==1
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel B25 = "`mean'%"
	su bthord_old3 if TIPO_old==2
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel C25 = "`mean'%"
	su bthord_old3 if TIPO_old==3
	local mean = string(100*`r(mean)',"%8.1f")
	putexcel D25 = "`mean'%"
	xi: xtreg bthord_old3 i.TIPO_old,  fe i(CENTRO_SALUD)
	matlist r(table)
	matrix I =r(table)
	local p1 = string(I[4,1],"%9.3f")
	local p2 = string(I[4,2],"%9.3f")
	putexcel E25 = "`p1'"
	putexcel F25 = "`p2'"
		
* End of dofile 


